home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Warrior INIT folder / INIT.c next >
C/C++ Source or Header  |  1994-03-07  |  3KB  |  114 lines

  1. /* #include files */
  2.  
  3. #include "A4Stuff.h"
  4. #include "SetupA4.h"
  5. #include "TestGlobals.h"
  6.  
  7. /* #defines */
  8.  
  9. #define kINITid            0
  10.  
  11. #define SEGMENTED        true        /* define if we have a multiple segment INIT */
  12. #define kNumSegments    2            /* total number of segments, including INIT resource itself */
  13.  
  14. /* some globals local to this file */
  15.  
  16. long    gLong;
  17. short    gShort;
  18. char    gChar;
  19.  
  20. /* SystemTask patch stuff */
  21.  
  22. typedef pascal void (*SystemTaskProc)(void);
  23. SystemTaskProc    gOldSystemTaskAddr;
  24. pascal void SystemTaskPatch(void);
  25.  
  26. /* main */
  27.  
  28. void main(void)
  29. {
  30.     long    oldA4;
  31.     Handle    h;
  32.     
  33.     #ifdef USE_DEBUGGER_CALLS
  34.         Debugger();
  35.     #endif
  36.  
  37.     /* set up our A4 context for _this file_ */
  38.     oldA4 = SetCurrentA4();
  39.     RememberA4();
  40.     
  41.     /* detach ourselves */
  42.     h = Get1Resource('INIT', kINITid);
  43.     if (h) DetachResource(h);
  44.         
  45.     /* initialize the globals in _this file_ */
  46.     gLong = kLongValue;
  47.     gShort = kShortValue;
  48.     gChar = kCharValue;
  49.     gOldSystemTaskAddr = 0L;
  50.     
  51.     /* initialize the globals in the _other file_ */
  52.     /* this also forces the code in the other segment to be loaded */
  53.     /* we must force all other segments to be loaded at this point */
  54.     /* so we can detach them below */
  55.     InitGlobals(kLongValue, kShortValue, kCharValue);
  56.     
  57.     /* now that we are sure that all segments have been loaded */
  58.     /* (since we called at least one routine in each segment) */
  59.     /* we can continue by detaching each one */
  60. #ifdef SEGMENTED    
  61.     {
  62.         short i;
  63.         for (i=kINITid+1;i<kNumSegments;++i) {
  64.             h = Get1Resource('INIc', i);    /* should NOT fail since each segment should already be loaded and locked */
  65.             if (h) DetachResource(h);
  66.         }
  67.     }
  68. #endif
  69.  
  70.     /* patch SystemTask */
  71.     gOldSystemTaskAddr = (SystemTaskProc)GetToolTrapAddress(_SystemTask);
  72.     SetToolTrapAddress((UniversalProcPtr)SystemTaskPatch, _SystemTask);
  73.     
  74.     /* restore the a4 world */
  75.     SetA4(oldA4);
  76. }
  77.  
  78. /* SystemTaskPatch */
  79.  
  80. pascal void SystemTaskPatch(void)
  81. {
  82.     long oldA4;
  83.     
  84.     #ifdef USE_DEBUGGER_CALLS
  85.         Debugger();
  86.     #endif
  87.     
  88.     /* use the global data in _this file_ */
  89.     oldA4 = SetUpA4();
  90.     
  91.     /* verify the globals in _this file_ */
  92.     if (gLong != kLongValue) SysBeep(0);
  93.     if (gShort != kShortValue) SysBeep(0);
  94.     if (gChar != kCharValue) SysBeep(0);
  95.  
  96.     /* test the globals in the _other file_ */
  97.     TestGlobals();
  98.     
  99.     /* call through to the original SystemTask */
  100.     gOldSystemTaskAddr();
  101.     
  102.     /* test the globals in the _other file_ again */
  103.     TestGlobals();
  104.     
  105.     /* verify the globals in _this file_ again */
  106.     if (gLong != kLongValue) SysBeep(0);
  107.     if (gShort != kShortValue) SysBeep(0);
  108.     if (gChar != kCharValue) SysBeep(0);
  109.  
  110.     /* restore the a4 world */
  111.     RestoreA4(oldA4);
  112. }
  113.  
  114.